//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.ehome.plugin.util;

import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;

public class Utils {
    private static final String TAG = "Utils";
    public static final int BUFFER_SIZE = 16384;

    public Utils() {
    }

    public static void copyFileUsingStream(File source, File dest) throws IOException {
        FileInputStream is = null;
        FileOutputStream os = null;
        File parent = dest.getParentFile();
        if (parent != null && !parent.exists()) {
            parent.mkdirs();
        }

        try {
            is = new FileInputStream(source);
            os = new FileOutputStream(dest, false);
            byte[] buffer = new byte[16384];

            int length;
            while((length = is.read(buffer)) > 0) {
                os.write(buffer, 0, length);
            }
        } finally {
            closeQuietly((Closeable)is);
            closeQuietly((Closeable)os);
        }

    }

    public static void closeQuietly(Closeable closeable) {
        try {
            if (closeable != null) {
                closeable.close();
            }
        } catch (IOException var2) {
            Log.w("Utils", "Failed to close resource", new Object[]{var2});
        }

    }

    public static boolean isRealZipOrJar(File input) {
        ZipFile zf = null;

        boolean var3;
        try {
            zf = new ZipFile(input);
            boolean var2 = true;
            return var2;
        } catch (Exception var7) {
            var3 = false;
        } finally {
            closeQuietly((Closeable)zf);
        }

        return var3;
    }

    public static void closeQuietly(Object obj) {
        if (obj != null) {
            if (obj instanceof Closeable) {
                try {
                    ((Closeable)obj).close();
                } catch (Throwable var4) {
                }
            } else if (obj instanceof AutoCloseable) {
                try {
                    ((AutoCloseable)obj).close();
                } catch (Throwable var3) {
                }
            } else {
                if (!(obj instanceof ZipFile)) {
                    throw new IllegalArgumentException("obj " + obj + " is not closeable");
                }

                try {
                    ((ZipFile)obj).close();
                } catch (Throwable var2) {
                }
            }

        }
    }

    public static void addZipEntry(ZipOutputStream zipOutputStream, ZipEntry zipEntry, InputStream inputStream) throws Exception {
        try {
            zipOutputStream.putNextEntry(zipEntry);
            byte[] buffer = new byte[16384];

            int length;

            while((length = inputStream.read(buffer, 0, buffer.length)) != -1) {
                zipOutputStream.write(buffer, 0, length);
                zipOutputStream.flush();
            }
        } catch (ZipException var8) {
            Log.e("Utils", "addZipEntry err!", new Object[0]);
        } finally {
            closeQuietly((Closeable)inputStream);
            zipOutputStream.closeEntry();
        }

    }
}
